package cn.mothin.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mothin.entity.FunctionItem;
import cn.mothin.frame.core.base.BaseDao;

@Repository("935c3336-5537-4d79-9fbf-4fd567765806")
public class FunctionItemDao extends BaseDao<FunctionItem> {
	public List<FunctionItem> querySub(String moduleId, String parentId) {
		if (parentId == null) {
			String sql = "SELECT * FROM function_item WHERE id NOT IN (select id FROM not_menu_item) AND parentId IS NULL AND functionModuleId=? ORDER BY name";
			return query(sql, moduleId);
		} else {
			String sql = "SELECT * FROM function_item WHERE id NOT IN (select id FROM not_menu_item) AND parentId =? AND functionModuleId=? ORDER BY name";
			return query(sql, parentId, moduleId);
		}
	}

	// 2013-05-24
	public List<FunctionItem> querySub(String moduleItemId, String parentId, String roleId) {
		if (parentId == null) {
			String sql = "SELECT * FROM function_item WHERE id NOT IN (select id FROM not_menu_item) AND parentId IS NULL AND id IN (SELECT id FROM function_item WHERE functionModuleId=?) AND id IN (SELECT moduleItemId FROM role_module_permission WHERE targetId= ? ) ORDER BY name";
			return query(sql, moduleItemId, roleId);
		} else {
			String sql = "SELECT * FROM function_item WHERE id NOT IN (select id FROM not_menu_item) AND parentId=? AND id IN (SELECT id FROM function_item WHERE functionModuleId=?) AND id IN (SELECT moduleItemId FROM role_module_permission WHERE targetId= ? ) ORDER BY name";
			return query(sql, parentId, moduleItemId, roleId);
		}
	}
}
